<style lang="scss" scope>
.content {
  width: 100%;
  height: 70px;
  padding: 10px;
  background: #f7f7ff;
  font-size: 18px;
  display: flex;
  .right {
    margin-left: 20px;
    text-align: center;
    align-content: center;
  }
}
.box {
  width: 100%;
  height: 100%;
  padding: 10px;
}
footer {
  padding: 10px;
  width: 95%;
  height: 50px;
  position: fixed;
  bottom: 15px;
}
</style>

<template>
  <div class="box">
    <header>
      <van-nav-bar
        left-arrow
        @click-left="$router.back()"
        title="网上预约挂号_在线资讯"
      />
    </header>
    <div class="c1" v-if="v">
      <h2>就诊信息</h2>
      <van-cell title="就诊日期" :value="currentTime" size="large" />
      <van-cell title="出诊医生" :value="v[0].doctorname" size="large" />
      <van-cell title="就诊科室" :value="v[0].doctoradministre" size="large" />
      <van-cell title="就诊医院" :value="v[0].nosocomium" size="large" />
      <van-cell title="挂号费用" :value="v[0].doctorgood" size="large" />
    </div>

    <div class="c2">
      <h2>选择就诊人</h2>
      <!-- @vue-ignore -->
      <div v-if="userdata.value == ''">
        <van-button
          type="success"
          round
          size="large"
          @click="$router.push('/Visit')"
        >
          添加就诊人
        </van-button>
      </div>
      <div v-else>
        <div
          v-for="(item, index) in userdata.slice(0, 1)"
          :key="index"
          class="content"
          @click="$router.push('/userAdd')"
        >
          <div class="left" >
            <div style="color: aqua">
              {{ item.username }}

              <span>已实名</span>
            </div>
            <div style="font-size: 13px;">居民身份证{{ item.userstanding }}</div>
          </div>

          <div class="right">更换></div>
        </div>
      </div>
    </div>

    <div class="c3">
      <h2>疾病/症状</h2>
      <van-cell-group inset>
        <van-field
          rows="2"
          autosize
          type="textarea"
          maxlength="15"
          placeholder="简述您的症状(2-15字)"
          show-word-limit
        />
      </van-cell-group>
    </div>

    <footer>
      <van-button type="success" round size="large" @click="handGuahao(v)">
        立即预约
      </van-button>
    </footer>
  </div>
</template>

<script setup lang="ts">
import {  ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import type {userState} from '@/interface/index' 
import axios from 'axios'
const router = useRouter()
const currentTime = ref<any>(new Date().toLocaleString())
const route = useRoute()
const id = route.params.id
const v = ref()
const yy = ref()
const getDetailData = async () => {
  const res = await axios.get('/api/doctor/detail', { params: { id: id } })
  v.value = res.data.data

  yy.value = res.data.data[0]
}
getDetailData()

const userdata = ref<userState[]>([])
const config = ref<any>({
  name: '',
  standing: '',
  birthday: '',
  sex: '',
  phone: '',
  relation: '',
  age: 0,
})

const getData = async () => {
  const res = await axios.get('/api/user/list', config.value)

  const { data } = res.data
  console.log(data);

  userdata.value = data
}
getData()

const getList = async () => {
  const res = await axios.put('/api/order', {
    doctor: id,
    user: userdata.value[0].username,
    time: currentTime.value,
    price: userdata.value[1],
  })
  

  const { data } = res.data
  console.log(data);
  
}
getList()

const get = async () => {
  const res = await axios.get('/api/order')
  const { data } = res.data
  console.log(data)
}
get()

const handGuahao = (v: string) => {
  getList()
  router.push(`/Guahao/${id}`)
}

</script>
